package com.ruoyi.api.controller;

import com.ruoyi.api.service.ChatUserService;
import com.ruoyi.api.service.VimGroupApiService;
import com.ruoyi.api.service.VimUserApiService;
import com.ruoyi.api.vo.ChatUser;
import com.ruoyi.common.core.domain.AjaxResult;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 北斗通信
 */
@RestController
@RequestMapping("/api/sys/chatuser")
public class ChatUserController {

    @Autowired
    private ChatUserService chatUserService;

    @Autowired
    private VimUserApiService vimUserApiService;

    @Autowired
    private VimGroupApiService vimGroupApiService;

    @PostMapping(value = "selectUser")
    public AjaxResult selectUser(@RequestBody Long userId) {
        List<String> longs = vimUserApiService.selectfriend(String.valueOf(userId));
        longs.add(String.valueOf(userId));
        //查询用户好友，并查询其北斗号
        List<ChatUser> list = new ArrayList<>();
        for (String aLong : longs) {
            ChatUser chatUser1 = chatUserService.selectUser(aLong);
            if(chatUser1 != null){
                chatUser1.setGFlag(1);
                if(chatUser1.getBdNumber() == null && chatUser1.getBdNumber().equals(" ")){
                    chatUser1.setStatus(1);
                }else {
                    chatUser1.setStatus(2);
                }
                list.add(chatUser1);
            }
        }
        //查询用户群组，并查询其北斗号
        List<String> lists = vimGroupApiService.selectgroup(userId);
        for (String s : lists) {
            ChatUser chatUser1 = chatUserService.selectUser(s);
            if(chatUser1 != null){
                chatUser1.setGFlag(1);
                if(chatUser1.getBdNumber() == null && chatUser1.getBdNumber().equals(" ")){
                    chatUser1.setStatus(1);
                }else {
                    chatUser1.setStatus(2);
                }
                list.add(chatUser1);
            }
        }

        return AjaxResult.success(list);
    }
}
